#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long

ll qpow(ll a, ll b, ll p) { 
	ll res = 1;
	while (b) {
		if (b & 1) res = res * a % p;
		a = a * a % p;
		b >>= 1;
	}
	return res;
}

int main() {
	ll a, b, p; cin >> a >> b >> p;
	printf("%lld^%lld mod %lld=%lld\n", a,b,p,qpow(a,b,p));
	return 0;
}